opentelemetry-api: remove env carrier environment snapshot caching#5366
Open
pellared wants to merge 2 commits into
Open
opentelemetry-api: remove env carrier environment snapshot caching#5366pellared wants to merge 2 commits into
pellared wants to merge 2 commits into
Conversation
Member
Author
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the opentelemetry-api environment carrier so EnvironmentGetter no longer snapshots os.environ at construction time, and instead reads directly from the provided carrier mapping at lookup time (aligning with the linked spec change and avoiding an upfront full-environment scan).
Changes:
- Remove
EnvironmentGetter’s initialization-time snapshot and read values from the supplied carrier inget(). - Update
keys()to return only already-normalized keys from the supplied carrier. - Adjust env-carrier propagator tests to pass
os.environ(or a dict carrier) intoextract()/get()accordingly, and add a changelog entry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| opentelemetry-api/src/opentelemetry/propagators/_envcarrier.py | Removes env snapshot caching; EnvironmentGetter now reads from the passed carrier and filters normalized keys from it. |
| opentelemetry-api/tests/propagators/test__envcarrier.py | Updates tests to pass the carrier mapping (including os.environ) to match the new getter behavior and adds coverage for non-snapshot behavior. |
| .changelog/5366.changed | Records the behavioral/performance change in the changelog system. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
adrielp
approved these changes
Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows open-telemetry/opentelemetry-specification#5179
Update
EnvironmentGetterto read from the supplied carrier mapping at lookup time, while still normalizing requested keys and returning only already-normalized keys fromkeys().There is a performance motivation for removing the snapshot. The previous implementation scanned and copied the full process environment when
EnvironmentGetterwas constructed, even though extraction normally reads only a small, fixed set of propagation keys such asTRACEPARENT,TRACESTATE, andBAGGAGE. Reading directly from the supplied carrier avoids that upfront O(n) environment scan and keeps work proportional to the keys actually requested by the propagator